package cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemdn;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemdn.vo.GiItemDnPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemdn.vo.GiItemDnRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.giitem.giitemdn.vo.GiItemDnSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.giitem.GiItemDnDO;
import cn.iocoder.yudao.module.erp.service.giitem.GiItemDnService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

@Tag(name = "管理后台 - ERP物流东宁仓库货号详情")
@RestController
@RequestMapping("/erp/gi-item-dn")
@Validated
public class GiItemDnController {

    @Resource
    private GiItemDnService giItemDnService;

    @PostMapping("/create")
    @Operation(summary = "创建ERP物流东宁仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dn:create')")
    public CommonResult<String> createGiItemDn(@Valid @RequestBody GiItemDnSaveReqVO createReqVO) {
        return success(giItemDnService.createGiItemDn(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新ERP物流东宁仓库货号详情")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dn:update')")
    public CommonResult<Boolean> updateGiItemDn(@Valid @RequestBody GiItemDnSaveReqVO updateReqVO) {
        giItemDnService.updateGiItemDn(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除ERP物流东宁仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dn:delete')")
    public CommonResult<Boolean> deleteGiItemDn(@RequestParam("id") Long id) {
        giItemDnService.deleteGiItemDn(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得ERP物流东宁仓库货号详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dn:query')")
    public CommonResult<GiItemDnRespVO> getGiItemDn(@RequestParam("id") Long id) {
        GiItemDnDO giItemDn = giItemDnService.getGiItemDn(id);
        return success(BeanUtils.toBean(giItemDn, GiItemDnRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得ERP物流东宁仓库货号详情分页")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dn:query')")
    public CommonResult<PageResult<GiItemDnRespVO>> getGiItemDnPage(@Valid GiItemDnPageReqVO pageReqVO) {
        PageResult<GiItemDnDO> pageResult = giItemDnService.getGiItemDnPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, GiItemDnRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出ERP物流东宁仓库货号详情 Excel")
    // @PreAuthorize("@ss.hasPermission('erp:gi-item-dn:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportGiItemDnExcel(@Valid GiItemDnPageReqVO pageReqVO,
                                    HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<GiItemDnDO> list = giItemDnService.getGiItemDnPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "ERP物流东宁仓库货号详情.xls", "数据", GiItemDnRespVO.class,
                BeanUtils.toBean(list, GiItemDnRespVO.class));
    }

}